﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MAF.CRUD;
using Domain.Entities;

namespace Database.Persistence
{
    public abstract class DBFactory
    {
        public virtual CategoryCollection CreateCategory()
        {
            throw new NotImplementedException();
        }

        public virtual ArticleCollection CreateArticle()
        {
            throw new NotImplementedException();
        }

        public virtual ProductCollection CreateProduct()
        {
            throw new NotImplementedException();
        }

        public virtual MessageCollection CreateMessage()
        {
            throw new NotImplementedException();
        }

        public virtual DealerCollection CreateDealer()
        {
            throw new NotImplementedException();
        }

        public static DBFactory GetInstance(string module)
        {
            switch (module)
            {
                case "News":
                    return new NewsDBFactory();
                case "Knowledge":
                    return new KnowledgeDBFactory();
                case "Company":
                    return new CompanyDBFactory();
                case "NnjKnowledge":
                    return new NnjKnowledgeDBFactory();
                case "NnjBrand":
                    return new NnjBrandDBFactory();
                case "Triliph":
                    return new TriliphDBFactory();
                case "NuenJane":
                    return new NuenJaneDBFactory();
                case "Dealer":
                    return new DealerDBFactory();
                case "Message":
                    return new MessageDBFactory();
                default:
                    throw new ArgumentException(string.Format("不支持“{0}”模块，是不是在UI中忘了为Module字段赋值？", module));
            }
        }
    }

    public class NewsDBFactory : DBFactory
    {
        public override CategoryCollection CreateCategory()
        {
            return new CategoryCollection("SqlMap.config", "NewsCategory");
        }

        public override ArticleCollection CreateArticle()
        {
            return new ArticleCollection("SqlMap.config", "News");
        }
    }

    public class KnowledgeDBFactory : DBFactory
    {
        public override CategoryCollection CreateCategory()
        {
            return new CategoryCollection("SqlMap.config", "KnowledgeCategory");
        }

        public override ArticleCollection CreateArticle()
        {
            return new ArticleCollection("SqlMap.config", "Knowledge");
        }
    }

    public class CompanyDBFactory : DBFactory
    {
        public override CategoryCollection CreateCategory()
        {
            return new CategoryCollection("SqlMap.config", "CompanyCategory");
        }

        public override ArticleCollection CreateArticle()
        {
            return new ArticleCollection("SqlMap.config", "Company");
        }
    }

    public class TriliphDBFactory : DBFactory
    {
        public override CategoryCollection CreateCategory()
        {
            return new CategoryCollection("SqlMap.config", "TriliphCategory");
        }

        public override ProductCollection CreateProduct()
        {
            return new ProductCollection("SqlMap.config", "Triliph");
        }
    }

    public class NuenJaneDBFactory : DBFactory
    {
        public override CategoryCollection CreateCategory()
        {
            return new CategoryCollection("SqlMap.config", "NuenJaneCategory");
        }

        public override ProductCollection CreateProduct()
        {
            return new ProductCollection("SqlMap.config", "NuenJane");
        }
    }

    public class NnjKnowledgeDBFactory : DBFactory
    {
        public override CategoryCollection CreateCategory()
        {
            return new CategoryCollection("SqlMap.config", "NnjKnowledgeCategory");
        }

        public override ArticleCollection CreateArticle()
        {
            return new ArticleCollection("SqlMap.config", "NnjKnowledge");
        }
    }

    public class NnjBrandDBFactory : DBFactory
    {
        public override CategoryCollection CreateCategory()
        {
            return new CategoryCollection("SqlMap.config", "NnjBrandCategory");
        }

        public override ArticleCollection CreateArticle()
        {
            return new ArticleCollection("SqlMap.config", "NnjBrand");
        }
    }

    public class MessageDBFactory : DBFactory
    {
        public override MessageCollection  CreateMessage()
        {
            return new MessageCollection("SqlMap.config", "Message");
        }
    }

    public class DealerDBFactory : DBFactory
    {
        public override DealerCollection CreateDealer()
        {
            return new DealerCollection("SqlMap.config", "Dealer");
        }
    }

}